package com.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.dao.CourseDao;
import com.opensymphony.xwork2.ActionContext;
import com.po.CourseInfoVO;
@Controller
public class CourseAction {
	@Autowired
	private CourseDao courseDao;
	/**
	 * 查询java课程
	 * @return
	 */
	public String showJavaCourse() {
		//拿到该课程的ID值
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		
		List<CourseInfoVO> list = courseDao.findCourse(id); 
		HashMap<String,List> map = new LinkedHashMap<String, List>();
		
		
		//将java课程等级名称作为key，等级中的技能作为value
		List<CourseInfoVO> list1;
		for (CourseInfoVO classInfoVO : list) {
				if(map.containsKey(classInfoVO.getCourse_name()) == true){
					list1 = map.get(classInfoVO.getCourse_name());
				}else{
					list1 = new ArrayList<CourseInfoVO>();
				}
				list1.add(classInfoVO);
				map.put(classInfoVO.getCourse_name(), list1);
		}
		ActionContext.getContext().put("map",map);
		return "course_java";
	}

	
	/**
	 * 查询安卓课程
	 * @return
	 */
	public String showAndroidCourse() {
		//拿到该课程的ID值
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		
		List<CourseInfoVO> list = courseDao.findCourse(id); 
		HashMap<String,List> map = new LinkedHashMap<String, List>();
		
		
		//将java课程等级名称作为key，等级中的技能作为value
		List<CourseInfoVO> list1;
		for (CourseInfoVO classInfoVO : list) {
				if(map.containsKey(classInfoVO.getCourse_name()) == true){
					list1 = map.get(classInfoVO.getCourse_name());
				}else{
					list1 = new ArrayList<CourseInfoVO>();
				}
				list1.add(classInfoVO);
				map.put(classInfoVO.getCourse_name(), list1);
		}
		ActionContext.getContext().put("map",map);
		return "course_ad";
	}
	/**
	 * 查询PHP课程
	 * @return
	 */
	public String showPhPCourse() {
		//拿到该课程的ID值
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		
		List<CourseInfoVO> list = courseDao.findCourse(id); 
		HashMap<String,List> map = new LinkedHashMap<String, List>();
		
		
		//将java课程等级名称作为key，等级中的技能作为value
		List<CourseInfoVO> list1;
		for (CourseInfoVO classInfoVO : list) {
				if(map.containsKey(classInfoVO.getCourse_name()) == true){
					list1 = map.get(classInfoVO.getCourse_name());
				}else{
					list1 = new ArrayList<CourseInfoVO>();
				}
				list1.add(classInfoVO);
				map.put(classInfoVO.getCourse_name(), list1);
		}
		ActionContext.getContext().put("map",map);
		return "course_php";
	}
	/**
	 * 查询web前端课程
	 * @return
	 */
	public String showWebCourse() {
		//拿到该课程的ID值
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		
		List<CourseInfoVO> list = courseDao.findCourse(id); 
		HashMap<String,List> map = new LinkedHashMap<String, List>();
		
		
		//将java课程等级名称作为key，等级中的技能作为value
		List<CourseInfoVO> list1;
		for (CourseInfoVO classInfoVO : list) {
				if(map.containsKey(classInfoVO.getCourse_name()) == true){
					list1 = map.get(classInfoVO.getCourse_name());
				}else{
					list1 = new ArrayList<CourseInfoVO>();
				}
				list1.add(classInfoVO);
				map.put(classInfoVO.getCourse_name(), list1);
		}
		ActionContext.getContext().put("map",map);
		return "course_web";
	}
	
	


}
